/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.controller;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import br.ufmg.dees.insane.commons.controller.Controller;
import br.ufmg.dees.insane.commons.view.DrawingArea;
import br.ufmg.dees.insane.draw.CubicCurveDraw;
import br.ufmg.dees.insane.draw.CurveDraw;
import br.ufmg.dees.insane.draw.Draw;
import br.ufmg.dees.insane.draw.LineDraw;
import br.ufmg.dees.insane.draw.LoftingRegionDraw;
import br.ufmg.dees.insane.draw.PointDraw;
import br.ufmg.dees.insane.draw.QuadCurveDraw;
import br.ufmg.dees.insane.draw.RegionDraw;
import br.ufmg.dees.insane.model.Model;
import br.ufmg.dees.insane.model.geo.GCubicCurve;
import br.ufmg.dees.insane.model.geo.GCurve;
import br.ufmg.dees.insane.model.geo.GLine;
import br.ufmg.dees.insane.model.geo.GPoint;
import br.ufmg.dees.insane.model.geo.GQuadCurve;
import br.ufmg.dees.insane.model.geo.GRegion;
import br.ufmg.dees.insane.model.geo.GeometricModel;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;
import br.ufmg.dees.insane.util.IPoint3d;

/**
 * @author Pitangueira, Roque & Brugiolo, Marco & Fonseca, Flavio
 * @version 0.0.1 Beta
 * @since jdk1.4.1
 */
public class RegionController implements Controller {

	private InsaneInternalInterface parent;
	private Model model;
	private GeometricModel gmodel;
	private DrawingArea da;
	private ArrayList<Draw> ctrlPoints = new ArrayList<Draw>();
	private ArrayList<Draw> points = new ArrayList<Draw>();
	private ArrayList<Draw> lines = new ArrayList<Draw>();
	private ArrayList<Draw> quads = new ArrayList<Draw>();
	private ArrayList<Draw> cubics = new ArrayList<Draw>();
	private ArrayList<Draw> curves = new ArrayList<Draw>();
	private ArrayList<Draw> regions = new ArrayList<Draw>();
	private ArrayList<Object> newCurves = new ArrayList<Object>();
	private ArrayList<Object> selections = new ArrayList<Object>();
	
	private int labelCurve = 0;
	private int labelRegion = 0;
	
//*****************************************************************************
	
	/**
	 * The constructor method
	 *
	 * @param     parent   the parent of the class.
	 * @see       gui.Interface
	 */
	public RegionController(InsaneInternalInterface parent, Model model, DrawingArea da) {
		this.parent = parent;
		this.model = model;
		this.da = da;
		this.gmodel = this.model.getGModel();
		labelCurve = gmodel.getCurves().size();
		labelRegion = gmodel.getRegions().size();
	}
	
//*****************************************************************************
	
    public void draw(Graphics2D g) {
		
        double nodeScale = model.getState().nodeScale;
        g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		
		Draw draw;
		Point2D p;
		Point ctrl;
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			draw = (Draw)rgs.next();
			g.setColor( model.getState().regionColor );
			draw.draw(g);
			if ( model.getState().getViewRegionLabel() ) {
				g.setColor( Color.black );
				//draw.drawLabel(g);
			}
		}
		
		g.setColor( model.getState().curveColor);
		ListIterator cvs = newCurves.listIterator();
		while(cvs.hasNext()) {
			GCurve cv = (GCurve)cvs.next();
			draw = new CurveDraw(da, cv);
			draw.draw(g);
		}
		
		ListIterator cbs = cubics.listIterator();
        while(cbs.hasNext()) {
            draw = (Draw)cbs.next();
			GCubicCurve gc = (GCubicCurve)draw.getRepresents();
			p = gc.getCtrl1();
			ctrl= da.getViewPoint(p);
			draw.setControl(ctrl);
			p = gc.getCtrl2();
			ctrl= da.getViewPoint(p);
			draw.setControl2(ctrl);
			g.setColor(gc.getColor());
            draw.draw(g);
        }
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (QuadCurveDraw)qcs.next();
			GQuadCurve gq = (GQuadCurve)draw.getRepresents();
			p = gq.getCtrl();
			ctrl= da.getViewPoint(p);
			draw.setControl(ctrl);
			g.setColor(gq.getColor());
			draw.draw(g);
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			GLine gl = (GLine)draw.getRepresents();
			g.setColor(gl.getColor());
			draw.draw(g);
		}
		
		g.setColor( model.getState().pointColor);
		ListIterator pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			GPoint gp = (GPoint)draw.getRepresents();
			g.setColor(gp.getColor());
			draw.setScale(nodeScale);
			draw.draw(g);
		}
    }
    
//*****************************************************************************
	
    public void fit() {
        
        //Calculating bounds
        if (points.size() >= 2){
            Point leftUp = new Point();
            Point rightDown = new Point();
            PointDraw po;
            ListIterator pts = points.listIterator();
            po = (PointDraw)pts.next();
            leftUp.x = po.getLocation().x;
            leftUp.y = po.getLocation().y;
            rightDown.x = po.getLocation().x;
            rightDown.y = po.getLocation().y;
            while (pts.hasNext()){
                po = (PointDraw)pts.next();
                if (po.getLocation().x < leftUp.x){
                    leftUp.x = po.getLocation().x;
                }
                if (po.getLocation().x > rightDown.x){
                    rightDown.x = po.getLocation().x;
                }
                if (po.getLocation().y < leftUp.y){
                    leftUp.y = po.getLocation().y;
                }
                if (po.getLocation().y > rightDown.y){
                    rightDown.y = po.getLocation().y;
                }
            }
            pts = ctrlPoints.listIterator();
            while (pts.hasNext()){
                po = (PointDraw)pts.next();
                if (po.getLocation().x < leftUp.x){
                    leftUp.x = po.getLocation().x;
                }
                if (po.getLocation().x > rightDown.x){
                    rightDown.x = po.getLocation().x;
                }
                if (po.getLocation().y < leftUp.y){
                    leftUp.y = po.getLocation().y;
                }
                if (po.getLocation().y > rightDown.y){
                    rightDown.y = po.getLocation().y;
                }
            }
            
            //Adding some border
            leftUp.x = leftUp.x - 15;
            leftUp.y = leftUp.y - 15;
            rightDown.x = rightDown.x + 15;
            rightDown.y = rightDown.y + 15;
            
            Point2D p1 = da.getWorldPoint(leftUp);
            Point2D p2 = da.getWorldPoint(rightDown);
            Rectangle2D r = new Rectangle2D.Double(p1.getX(), p2.getY(), p2.getX(), p1.getY());
            
			da.setZoom(r);
        }
    }
	
//*****************************************************************************
	
	public void add(Object obj) {
		
		if (obj instanceof GCurve) {
			GCurve cv = (GCurve)obj;
			if(!this.contains(cv)) {
				gmodel.add(cv);
				newCurves.add(cv);
				int nc = newCurves.size();
				parent.activeButton(nc);
				curves.add(new CurveDraw(da, cv));
			}
		}
		if (obj instanceof GRegion) {
			GRegion rg = (GRegion)obj;
			if(!this.contains(rg)) {
				gmodel.add(rg);
				newCurves.clear();
				parent.activeButton(0);
				if (rg.getCurves().size()==2)
					regions.add(new LoftingRegionDraw(da, rg));
				else
					regions.add(new RegionDraw(da, rg));
			}
		}
	}
	
//*****************************************************************************
	
    public boolean contains(Point2D po) {
        Point p = da.getViewPoint(po);
        Draw draw;
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
        return false;
    }
    
//*****************************************************************************
	
    public boolean contains(Line2D l) {
        Point  p1 = da.getViewPoint(l.getP1());
        Point  p2 = da.getViewPoint(l.getP2());
        Draw draw;
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.contains(p1) && draw.contains(p2)) {
                return true;
            }
        }
        
        return false;
    }
	
//*****************************************************************************
	
	public boolean contains(QuadCurve2D q) {
		return false;
	}
	
//*****************************************************************************
	
	public boolean contains(CubicCurve2D c) {
		return false;
	}
	
//*****************************************************************************
	
	public boolean contains(GCurve gc) {
		GCurve gcv;
		List curves = new ArrayList();
		
		curves = gmodel.getCurves();
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			gcv = (GCurve)cvs.next();
			if (gcv.getLabel() == gc.getLabel() ) {
				return true;
			}
		}
		return false;
	}
	
//*****************************************************************************
	
	public boolean contains(GRegion gr) {
		GRegion grg;
		
		ListIterator rgs = (gmodel.getRegions()).listIterator();
		while(rgs.hasNext()) {
			grg = (GRegion)rgs.next();
			if (grg.getLabel() == gr.getLabel() ) {
				return true;
			}
		}
		return false;
	}
	
//*****************************************************************************
	
    public Point pick(Point p) {
        
        Draw draw;
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return draw.getLocation();
            }
        }
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.contains(p)) {
                return draw.getLocation();
            }
        }
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)) {
				return draw.getLocation();
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)) {
				return draw.getLocation();
			}
		}
		return p;
	}
    
//*****************************************************************************
	
	public void remove(Object obj) {
		unSelectAll();
		this.compose();
	}
    
//*****************************************************************************
	
	public List removeSelection() {
		
        ArrayList<Object> sel = new ArrayList<Object>();
		CurveDraw cv;
		RegionDraw rd;
        int index;
		
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			cv = (CurveDraw)cvs.next();
			if (cv.isSelected()){
				GCurve c = (GCurve)cv.getRepresents();
				index = selections.indexOf(cv.getRepresents());
				selections.remove(index);
				sel.add(c);
			}
		}
		
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			rd = (RegionDraw)rgs.next();
			if (rd.isSelected()){
				GRegion r = (GRegion)rd.getRepresents();
				index = selections.indexOf(rd.getRepresents());
				selections.remove(index);
				sel.add(r);
			}
		}
		this.compose();
		unSelectAll();
        return sel;
    }
    
//*****************************************************************************
	
    public void removeAll() {
		gmodel.clearCurves();
		gmodel.clearRegions();
    }
	
//*****************************************************************************
    
    public void select(Point p) {
		Draw draw;
		int index;
		
		ListIterator pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.contains(p)) {	
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
	}
	
//*****************************************************************************
    
    public void selectAll() {
        Draw draw;
		selections.clear();
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            draw.setSelected(true);
			selections.add(draw.getRepresents());
        }
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            draw.setSelected(true);
			selections.add(draw.getRepresents());
        }
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			draw = (Draw)cvs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			draw = (Draw)rgs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
	}
	
//*****************************************************************************
	
	public void unSelectAll() {
		Draw draw;
		selections.clear();
		
		ListIterator pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setSelected(false);
		}
		
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            draw.setSelected(false);
        }
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			draw.setSelected(false);
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			draw.setSelected(false);
		}
		
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			draw = (Draw)cvs.next();
			draw.setSelected(false);
		}
		
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			draw = (Draw)rgs.next();
			draw.setSelected(false);
		}
    }
	
//*****************************************************************************
	
    public ArrayList getSelection() {
        return selections;
    }
	
//*****************************************************************************
	
	public void clearCurves() {
		labelCurve = 0;
		newCurves.clear();
		selections.clear();
		gmodel.clearCurves();
	}
	
//*****************************************************************************
	
	public void clearRegions() {
		labelRegion = 0;
		gmodel.clearRegions();
	}
	
//*****************************************************************************
	
	public ArrayList getNewCurves() {
		return newCurves;
	}
	
//*****************************************************************************
	
    public void compose() {
		ctrlPoints.clear();
		points.clear();
		lines.clear();
		quads.clear();
		cubics.clear();
		curves.clear();
		regions.clear();
		
		Point2D po;
		Point p;
		ListIterator pts = gmodel.getControlPoints().listIterator();
		while (pts.hasNext()) {
			po = (Point2D)pts.next();
			p = da.getViewPoint(po);
			ctrlPoints.add(new PointDraw(p, po));
		}
		
		pts = gmodel.getPoints().listIterator();
		while (pts.hasNext()) {
			po = (Point2D)pts.next();
			p = da.getViewPoint(po);
			points.add(new PointDraw(p, po));
		}
		
		Line2D li;
		Point p1;
		Point p2;
		ListIterator lns = gmodel.getLines().listIterator();
		while (lns.hasNext()) {
			li = (Line2D)lns.next();
			p1 = da.getViewPoint(li.getP1());
			p2 = da.getViewPoint(li.getP2());
			lines.add(new LineDraw(p1, p2, li));
		}
		
		QuadCurve2D qu;
		Point ctrl;
		ListIterator qds = gmodel.getQuads().listIterator();
		while (qds.hasNext()) {
			qu = (QuadCurve2D)qds.next();
			p1 = da.getViewPoint(qu.getP1());
			ctrl = da.getViewPoint(qu.getCtrlPt());
			p2 = da.getViewPoint(qu.getP2());
			quads.add(new QuadCurveDraw(p1, ctrl, p2, qu));
		}
		
		CubicCurve2D cb;
		Point ctrl1;
		Point ctrl2;
		ListIterator cbs = gmodel.getCubics().listIterator();
		while (cbs.hasNext()) {
			cb = (CubicCurve2D)cbs.next();
			p1 = da.getViewPoint(cb.getP1());
			ctrl1 = da.getViewPoint(cb.getCtrlP1());
			ctrl2 = da.getViewPoint(cb.getCtrlP2());
			p2 = da.getViewPoint(cb.getP2());
			cubics.add(new CubicCurveDraw(p1, ctrl1, ctrl2, p2, cb));
		}
		
		ListIterator cvs = gmodel.getCurves().listIterator();
		while (cvs.hasNext()) {
			GCurve cv = (GCurve)cvs.next();
			curves.add(new CurveDraw(da, cv));
		}
		
		ListIterator rgs = gmodel.getRegions().listIterator();
		while (rgs.hasNext()) {
			GRegion rg = (GRegion)rgs.next();
			if (rg.getCurves().size()==2)
				regions.add(new LoftingRegionDraw(da, rg));
			else
				regions.add(new RegionDraw(da, rg));
		}
	}
    
//*****************************************************************************
	
    public Object get(Point2D po) {
		Point location = da.getViewPoint(po);
        Draw draw;
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(location)) {
                return draw.getRepresents();
            }
        }
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.contains(location)){
                return draw.getRepresents();
            }
        }
        
		ListIterator qds = quads.listIterator();
		while(qds.hasNext()) {
			draw = (Draw)qds.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			draw = (Draw)cvs.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			draw = (Draw)rgs.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
        return null;
    }
    
//*****************************************************************************
	
    public boolean isSelected() {
        Draw draw;
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.isSelected()) {
                return true;
            }
        }
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.isSelected()){
                return true;
            }
        }
		
		ListIterator qds = quads.listIterator();
		while(qds.hasNext()) {
			draw = (Draw)qds.next();
			if (draw.isSelected()){
				return true;
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.isSelected()){
				return true;
			}
		}
		
		ListIterator cvs = curves.listIterator();
		while(cvs.hasNext()) {
			draw = (Draw)cvs.next();
			if (draw.isSelected()){
				return true;
			}
		}
		
		ListIterator rgs = regions.listIterator();
		while(rgs.hasNext()) {
			draw = (Draw)rgs.next();
			if (draw.isSelected()){
				return true;
			}
		}
		return false;
	}
	
//*****************************************************************************
	
	public List getRegions() {
		return gmodel.getRegions();
	}
	
//*****************************************************************************
	
	public int getLabelRegion() {
		labelRegion++;
		return labelRegion;
	}
	
//*****************************************************************************
	
	public List getCurves() {
		return gmodel.getCurves();
	}
	
//*****************************************************************************
	
	public int getLabelCurve() {
		labelCurve++;
		return labelCurve;
	}
	
//*****************************************************************************
	
	public Color getCurveColor() {
		return model.getState().curveColor;
	}
	
//*****************************************************************************
	
	public Color getLineColor() {
		return model.getState().lineColor;
	}
	
//*****************************************************************************
	
	public Color getBoundaryColor() {
		return model.getState().boundaryColor;
	}
	
//*****************************************************************************
	
	public void setColor() {
		Draw draw;
		Color gcColor = model.getState().lineColor;
		GCubicCurve gc;
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			gc = (GCubicCurve)draw.getRepresents();
			gc.setColor(gcColor);
		}
		
		Color gqColor = model.getState().lineColor;
		GQuadCurve gq;
		ListIterator qds = quads.listIterator();
		while(qds.hasNext()) {
			draw = (Draw)qds.next();
			gq = (GQuadCurve)draw.getRepresents();
			gq.setColor(gqColor);
		}
		
		Color glColor = model.getState().lineColor;
		GLine gl;
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			gl = (GLine)draw.getRepresents();
			gl.setColor(glColor);
		}
		
		Color gpColor = model.getState().pointColor;
		GPoint gp;
		ListIterator pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			gp = (GPoint)draw.getRepresents();
			gp.setColor(gpColor);
		}
	}

	public boolean contains(IPoint3d po) {
		// TODO Auto-generated method stub
		return false;
	}
	
//*****************************************************************************
}
